package com.yj.jason.baselibrary.view.MyRecyclerView;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class MySwipeRefreshLayout extends SwipeRefreshLayout{

    private boolean intercept;

    public MySwipeRefreshLayout(@NonNull Context context) {
        this(context,null);
    }

    public MySwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setColorSchemeColors(Color.RED,Color.BLUE,Color.GREEN);
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        intercept=super.onInterceptTouchEvent(ev);

        float lastx=0,lasty=0;


        switch (ev.getAction()){

            case MotionEvent.ACTION_DOWN:
                lastx=ev.getX();
                lasty=ev.getY();
                break;

            case MotionEvent.ACTION_MOVE:
                float curreutx=ev.getX();
                float currenty=ev.getY();


                if(Math.abs(currenty-lasty)>0&&Math.abs(currenty-lasty)-Math.abs(curreutx-lastx)>5){
                    intercept=false;
                }
                break;


        }

        return intercept;
    }
}
